package at.codejedi.sto.gui.combat.tree;

import java.text.DateFormat;
import java.util.Calendar;

import at.codejedi.sto.config.Configuration;
import at.codejedi.sto.model.combat.IPlayerBattle;

class PlayerBattleTreeNode extends TreeNodeWrapper<IPlayerBattle> {
	public enum DisplayType {
		BattleTime, PlayerName
	}

	private DisplayType t;

	public PlayerBattleTreeNode(IPlayerBattle battle, DisplayType t) {
		super(battle);
		this.t = t;
	}

	private String getBattleName(IPlayerBattle battle) {
		Calendar start = Calendar.getInstance();
		start.setTimeInMillis(battle.getBeginningMillis());

		DateFormat sdf = Configuration.getDateTimeFormat();
		return sdf.format(start.getTime());
	}

	private String getPlayerName(IPlayerBattle battle) {
		return battle.getPlayer().getPlayerName();
	}

	@Override
	public String toString() {
		IPlayerBattle wrappedObj = getWrappedObj();
		switch (t) {
		case BattleTime:
			return getBattleName(wrappedObj);
		case PlayerName:
			return getPlayerName(wrappedObj);
		}
		throw new IllegalStateException();
	}
}
